package com.swordget.controller;


import com.swordget.entity.Sys_DataSource;
import com.swordget.entity.vo.SimplePageRequestVo;
import com.swordget.entity.vo.SimplePageResponseVo;
import com.swordget.entity.vo.SimpleResponseVo;
import com.swordget.service.Sys_DataSourceService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/***
 *  跑批程序控制器
 * @author liang.xu
 * @date 2021.7.23
 */
@RestController
public class Sys_DataSourceController {

    @Resource
    private Sys_DataSourceService sysDataSourceService;


    @RequestMapping(value = "/sys_dataSourceData", method = RequestMethod.POST)
    public SimplePageResponseVo sys_dataSourceData(SimplePageRequestVo pageVo) {
        return sysDataSourceService.findAll(pageVo);
    }

    @RequestMapping(value = "/sys_dataSourceList", method = RequestMethod.GET)
    public List<Sys_DataSource> sys_dataSourceList()  {
        Sys_DataSource sysDataSource = new Sys_DataSource();
        sysDataSource.setDataSourceName("默认数据源");
        sysDataSource.setId("0000000000000000000");
        List<Sys_DataSource> sysDataSourceList = sysDataSourceService.findAll();
        sysDataSourceList.add(0, sysDataSource);
        return sysDataSourceList;
    }

    // 添加
    @RequestMapping(value = "/addSys_dataSource", method = RequestMethod.POST)
    public SimpleResponseVo addSys_dataSource(@RequestBody Sys_DataSource sys_DataSource) {
        boolean b = sysDataSourceService.addSys_dataSource(sys_DataSource);
        if (b) {
            return SimpleResponseVo.success();
        }
        return SimpleResponseVo.fail("处理失败");
    }

    // 修改
    @RequestMapping(value = "/editSys_dataSource", method = RequestMethod.POST)
    public SimpleResponseVo editSys_dataSource(@RequestBody Sys_DataSource sys_DataSource) {
        boolean b = sysDataSourceService.editSys_dataSource(sys_DataSource);
        if (b) {
            return SimpleResponseVo.success();
        }
        return SimpleResponseVo.fail("处理失败");
    }

    // 测试连接
    @RequestMapping(value = "/testSys_dataSource", method = RequestMethod.POST)
    public String testSys_dataSource(@RequestBody Sys_DataSource sys_DataSource) {
        return sysDataSourceService.testSys_dataSource(sys_DataSource);
    }
}